<?php
class Core_Abstract
{	
	protected $_data	= array();
	
	public function __construct($options = null)
	{
		if (!is_null($options))
		{
			if ($options instanceof Zend_Config)
			{
				$options	= $options->toArray();
			}
			
			$this->setOptions($options);
		}
	}
	
	public function setOptions(array $options)
	{
		foreach ($options as $key => $value) 
		{
			$this->__set($key, $value);		
		}
		
		return $this;
	}
		
	/*public function __call($name, $args)
	{
		$begin	= substr($name, 0, 3);
		$end	= strtolower(substr($name, 3,1)) . substr($name, 4);
		
		switch($begin)
		{
			case 'set':
				return $this->__set($end, $args[0]);
				break;
			case 'get':
				return $this->__get($end);
				break;
		}

		throw new Exception('Invalid call [' . $name . ']');
	}*/
	
	public function __set($name, $value)
	{
		$method		= 'set' . $name;
		if (method_exists($this, $method)) 
		{
			$this->$method($value);
			return $this;	
		}
		
		if(array_key_exists($name, $this->_data))
		{
			$this->_data[$name]	= $value;
			return $this;	
		}
	
		throw new Exception('Invalid property [' . $name . ']');
	}
	
	public function __get($name)
	{
		$method		= 'get' . $name;
		if (method_exists($this, $method)) 
		{
			return $this->$method();	
		}
		
		if(array_key_exists($name, $this->_data))
		{
			return $this->_data[$name];				
		}
		
		throw new Exception('Invalid property [' . $name . ']');
	}
	
	public function toArray()
	{
		return  $this->_data;
	}	
}